<template>
    <div class="main">
      <div class="loginArea">
        <input type="text" placeholder="请输入手机号登录" v-model="phone">
        <button @click="handleGetToken">登 &nbsp; 录</button>
      </div>
    </div>
</template>


<script>
// import {getUserToken,getScriptTitle} from '../api/http'
import axios from 'axios'
import md5 from 'md5'
import qs from 'qs'
export default {
  data(){
   return {
     phone:'',
    //  baseUrl:'http://192.168.111.31:80',
    baseUrl:'https://tiaodao.headlinetop.com',
     salt:''
   }
  },
  created(){
    this.getSalt()
    // getScriptTitle()
  },
  methods:{
    getSalt() {
      this.loading = true;
      axios.get(this.baseUrl + `/web/Index/getSignature`).then((res) => {
        console.log(res.data);
        if (res.data.code == 200) {
          let s = res.data.data;
          let year = new Date().getFullYear();
          let month =
            new Date().getMonth() + 1 < 10
              ? "0" + (new Date().getMonth() + 1)
              : new Date().getMonth() + 1;
          let day =
            new Date().getDate() < 10
              ? "0" + new Date().getDate()
              : new Date().getDate();
          this.salt = md5(s + year + month + day);
          console.log(s + year + month + day,year,month,day);
          
          sessionStorage.setItem('web-token',this.salt)
        }
      });
    },
    handleGetToken(){
      axios.get(this.baseUrl+`/web/Index/getUserToken?phone=`+this.phone,{
        headers:{
          "web-token":this.salt,
        }
      })
      .then((res)=>{
        console.log(res);
        let token=res.data.data
        sessionStorage.setItem('token',token)
        this.$router.push('/home')
      })
    },

  }
}
</script>
<style lang='css' scoped src="../assets/css/login.css"></style>
<style lang='less' scoped>

</style>
